import axios, { type AxiosRequestHeaders, type AxiosResponse} from "axios";
import pinia from "@/stores";
import {useSource} from "@/stores/ source";

/* 定义response对象的data接口 */
interface ResponseData<T> {
    code: number;
    data: T;
    message: string;
}

// 配置新建一个 axios 实例
const service = axios.create({
    baseURL: "/apis",
    timeout: 50000,
});

// 添加请求拦截器
service.interceptors.request.use((config) => {
    useSource(pinia).vueElementLoading = true
    return config
});

// 添加响应拦截器
service.interceptors.response.use(
    (response) =>{
        useSource(pinia).vueElementLoading = false
        return response
    },
    (error) =>{
        useSource(pinia).vueElementLoading = false
        return new Promise(() =>{})
    }
);

export default service;
